package com.shimmer.CRUD;

import com.shimmer.dao.UserDao;
import com.shimmer.entity.User;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Package com.shimmer.CRUD
 * @Author shimmer
 * @Date 2020/8/16 15:02
 * @TODO
 */
public class EditUser extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id = Integer.parseInt(req.getParameter("id"));
        User user = new UserDao().getUsersById(id);

        StringBuffer sb = new StringBuffer();
        sb.append("<form action='updateUser' method='post'>");
        sb.append("账户：<input type='text' name='name' value='%s'></br>");
        sb.append("密码：<input type='text' name='password' value='%s'></br>");
        sb.append("<input type='hidden' name='id' value='%d'>");
        sb.append("<input type='submit' value='修改'>");
        sb.append("</form>");
        String html = String.format(sb.toString(), user.getName(), user.getPassword(),user.getId());
        
        resp.setContentType("text/html;charset=UTF-8");
        resp.getWriter().write(html);
    }
}
